#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/dispatch.h>

#define ATTACH_POINT "myname"

/* We specify the header as being at least a pulse */
typedef struct _pulse msg_header_t;

/* Our real data comes after the header */
typedef struct _my_data {
    msg_header_t hdr;
	int eSensingDelay;
	int ePacingDelay;
	int eSensitivityValue;
	int ePulseWidth;
	int ePulseAmplitude;
	int ePacingRate;
	int eRefractoryPeriod;
	int eOperatingMode;
} my_data_t;

/*** Client Side of the code ***/
int programmer() {
    my_data_t msg;
    int fd;

    if ((fd = name_open(ATTACH_POINT, 0)) == -1) {
        return EXIT_FAILURE;
    }

    /* We would have pre-defined data to stuff here */
    msg.hdr.type = 0x00;
    msg.hdr.subtype = 0x00;

    // these are the values set
    // it is suppose to read from file
   	msg.eSensingDelay = 15;
   	msg.ePacingDelay = 15;
	msg.eSensitivityValue = 8;
	msg.ePulseWidth = 1;
	msg.ePulseAmplitude = 5;
	msg.ePacingRate = 80;
	msg.eRefractoryPeriod = 300;
	msg.eOperatingMode = 6;

    if (MsgSend(fd, &msg, sizeof(msg), NULL, 0) == -1) {
    	printf("Error");
    }

    /* Close the connection */
    name_close(fd);
    return EXIT_SUCCESS;
}

int main(int argc, char **argv) {
    int ret;

    printf("Running Programmer ... \n");
    ret = programmer();
    return ret;
}
